﻿Imports System.Data.OleDb
Imports System.Text
Imports System.Reflection
Imports System.Collections.Specialized

Public Class EnglishWordForm
    Private Sub MyButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Try

            '先做画面的CHECK
            If (Not (DoCheck())) Then
                Exit Sub
            End If

            If rad正常.Checked Then
                ReportConst.TypeReport = 0
            ElseIf rad单词模式.Checked Then
                ReportConst.TypeReport = 1
            ElseIf rad意思模式.Checked Then
                ReportConst.TypeReport = 2
            End If

            If Me.CheckBox1.Checked Then
                If rad多到少.Checked Then
                    ReportConst.EnglishOrderBy = 1
                Else
                    ReportConst.EnglishOrderBy = 0
                End If
            Else
                ReportConst.EnglishOrderBy = 2
            End If

            Dim cv As New CrystlViewer
            cv._ParamsValues.Add("TITLE", Me.Text)
            cv._Rt = CrystlViewer.ReportType.English

            If rad按时间范围.Checked Then
                ReportConst.EnglishTypeReport = 0
                cv._ParamsValues.Add("开始时间", Me.dtStartTime.Text.ToString())
                cv._ParamsValues.Add("结束时间", Me.dtEndTime.Text.ToString())
            ElseIf rad按备注.Checked Then
                ReportConst.EnglishTypeReport = 2
                cv._ParamsValues.Add("当前英语备注ID", 当前英语备注ID.ToString)
            ElseIf rad按打印记录.Checked Then
                ReportConst.EnglishTypeReport = 3
                Dim dt As String = Convert.ToDateTime(cbo报表打印时间.Text).ToString("yyyy-MM-dd HH:mm:ss")
                Dim strSql As String = "select * from printLog where [type]=0 and datetime([datetime])='" + dt + "'"
                Dim rs As ADODB.Recordset = ct.GetTable(strSql)
                Dim ids As String = ""
                If rs IsNot Nothing Then
                    If rs.EOF Then
                        rs.Close()
                        Return
                    Else
                        ids = CStr(rs.Fields("keys").Value.ToString())
                        rs.Close()
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
                        rs = Nothing
                    End If
                End If
                cv._ParamsValues.Add("编号列表", ids)
            Else
                ReportConst.EnglishTypeReport = 1
            End If

            cv._ParamsValues.Add("RowCount", Me.NumericUpDown2.Value)

            Using cv
                cv.ShowDialog()
            End Using

        Catch ex As Exception
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod().GetType()) 'A-2009-10-11 
        End Try

    End Sub

#Region "关闭窗体"
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
#End Region

#Region "画面的CHECK"
    Public Function DoCheck() As Boolean
        If rad按时间范围.Checked Then
            Dim strTimeStart As String = ""
            Dim strTimeEnd As String = ""
            strTimeStart = String.Format("{0:00}{1:00}{2:00}", dtStartTime.Value.Year, dtStartTime.Value.Month, dtStartTime.Value.Day)
            strTimeEnd = String.Format("{0:00}{1:00}{2:00}", dtEndTime.Value.Year, dtEndTime.Value.Month, dtEndTime.Value.Day)

            If strTimeStart > strTimeEnd Then
                ShowMessageBox("开始时间不能大于结束时间")
                Return False
            End If
        ElseIf rad按打印记录.Checked Then
            If cbo报表打印时间.Text.Trim = "" Then
                ShowMessageBox("没有打印记录")
                Return False
            End If
        End If
       
        Return True
    End Function
#End Region

    Private Sub 页面设置oolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 页面设置ToolStripMenuItem1.Click
        Using frm As PageSetting = New PageSetting(PageSetting.ReportType.English)
            frm.ShowDialog()
            frm.Dispose()
        End Using
    End Sub

    Dim itemMenu As System.Windows.Forms.ToolStripMenuItem
    Private Sub EnglishWordForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If itemMenu Is Nothing Then
            itemMenu = Me.ContextMenuStrip1.Items.Add("页面设置")
            AddHandler itemMenu.Click, AddressOf 页面设置oolStripMenuItem_Click
        End If

        Dim rs As ADODB.Recordset
        Dim strSql As String = "select * from printLog where [type]=0 order by datetime desc"
        rs = ct.GetTable(strSql)
        If rs IsNot Nothing Then
            While Not rs.EOF
                cbo报表打印时间.Items.Add(rs.Fields("datetime").Value.ToString())
                rs.MoveNext()
            End While
            rs.Close()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
            rs = Nothing
        End If

        If cbo报表打印时间.Items.Count > 0 Then
            cbo报表打印时间.SelectedIndex = 0
        End If

    End Sub

    Private Sub rad按时间范围_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rad按记录数.CheckedChanged, rad按时间范围.CheckedChanged, rad按打印记录.CheckedChanged, rad按备注.CheckedChanged
        If rad按时间范围.Checked Then
            gp时间范围.Enabled = True
            gp打印记录.Enabled = False
            gp备注.Enabled = False
        End If

        If rad按备注.Checked Then
            gp时间范围.Enabled = False
            gp打印记录.Enabled = False
            gp备注.Enabled = True
        End If

        If rad按记录数.Checked Then
            gp时间范围.Enabled = False
            gp打印记录.Enabled = False
            gp备注.Enabled = False
        End If

        If rad按打印记录.Checked Then
            gp时间范围.Enabled = False
            gp打印记录.Enabled = True
            gp备注.Enabled = False
        End If
    End Sub

    Private Sub CheckBox1_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckStateChanged
        If CheckBox1.Checked Then
            rad多到少.Enabled = True
            rad少到多.Enabled = True
        Else
            rad多到少.Enabled = False
            rad少到多.Enabled = False
        End If
    End Sub

    Dim 当前英语备注ID As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = "select * from MEMO where type=1"
            Dim 显示列 As New StringCollection
            显示列.Add("TITLE")
            frm.显示列 = 显示列
            frm.ShowDialog()
            If frm.返回值.Count > 0 Then
                当前英语备注ID = CInt(frm.返回值(0))
                txt备注.Text = CStr(frm.返回值(1))
            Else
                当前英语备注ID = 0
                txt备注.Text = ""
            End If
        End Using
    End Sub

    Private Sub cbo报表打印时间_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo报表打印时间.SelectedIndexChanged
        Dim dt As String = Convert.ToDateTime(cbo报表打印时间.Text).ToString("yyyy-MM-dd HH:mm:ss")
        Dim strSql As String = "select * from printLog where [type]=0 and datetime([datetime])='" + dt + "'"
        Dim rs As ADODB.Recordset = ct.GetTable(strSql)
        Dim ids As String = ""
        If rs IsNot Nothing Then
            If rs.EOF Then
                rs.Close()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
                Return
            Else
                ids = CStr(rs.Fields("keys").Value.ToString())
                rs.Close()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
                rs = Nothing
            End If
        End If
        If ids <> "" Then
            strSql = "select id,WORD from XSCENLISHWORD where id in(" + ids + " ) "
            Dim strSql1 As String = "select count(*) as PageCount from XSCENLISHWORD where id in( " + ids + " ) "
            rs = ct.GetTable(strSql1)
            If rs IsNot Nothing Then
                If rs.EOF Then
                    rs.Close()
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
                    Return
                Else
                    NumericUpDown2.Value = CInt(rs.Fields("PageCount").Value)
                    rs.Close()
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs) '20100531
                End If
            End If
        End If
    End Sub

#Region "窗体数据保存的重载方法 A-2010-09-06"
    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)
        If rad按记录数.Checked Then
            dtData.Rows.Add(New Object() {"类型", "", "正常"})
        ElseIf rad按时间范围.Checked Then
            dtData.Rows.Add(New Object() {"类型", "", "按时间范围"})
        ElseIf rad按备注.Checked Then
            dtData.Rows.Add(New Object() {"类型", "", "按备注"})
        ElseIf rad按打印记录.Checked Then
            dtData.Rows.Add(New Object() {"类型", "", "按打印记录"})
        End If

        '时间范围
        dtData.Rows.Add(New Object() {"时间范围.开始.年", "", dtStartTime.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"时间范围.开始.月", "", dtStartTime.Value.Month.ToString})
        dtData.Rows.Add(New Object() {"时间范围.开始.日", "", dtStartTime.Value.Day.ToString})

        dtData.Rows.Add(New Object() {"时间范围.结束.年", "", dtEndTime.Value.Year.ToString})
        dtData.Rows.Add(New Object() {"时间范围.结束.月", "", dtEndTime.Value.Month.ToString})
        dtData.Rows.Add(New Object() {"时间范围.结束.日", "", dtEndTime.Value.Day.ToString})

        '备注
        dtData.Rows.Add(New Object() {"备注.内容", "", txt备注.Text})
        dtData.Rows.Add(New Object() {"备注.编号", "", 当前英语备注ID.ToString})
        '打印记录
        '浏览条件
        If CheckBox1.Checked Then
            dtData.Rows.Add(New Object() {"浏览次数是否选中", "", "选中"})
        Else
            dtData.Rows.Add(New Object() {"浏览次数是否选中", "", "不选中"})
        End If
        If rad多到少.Checked Then
            dtData.Rows.Add(New Object() {"排序", "", "多到少"})
        Else
            dtData.Rows.Add(New Object() {"排序", "", "少到多"})
        End If
        '模式
        If rad正常.Checked Then
            dtData.Rows.Add(New Object() {"模式", "", "正常"})
        ElseIf rad单词模式.Checked Then
            dtData.Rows.Add(New Object() {"模式", "", "单词模式"})
        ElseIf rad意思模式.Checked Then
            dtData.Rows.Add(New Object() {"模式", "", "意思模式"})
        End If
        '记录数
        dtData.Rows.Add(New Object() {"记录数", "", NumericUpDown2.Value.ToString})
    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)
    
    End Sub

#End Region
End Class
